package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.StatisticsDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Version: V1.0
 */
@Api
@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController {

    @Autowired
    ApArticleService apArticleService;

    @ApiOperation("根据ID查询文章")
    @GetMapping("{id}")
    public ResponseResult<ApArticle> findArticle(@PathVariable Long id) {
        ApArticle apArticle = apArticleService.getById(id);
        return ResponseResult.okResult(apArticle);
    }

    @ApiOperation("根据时间查询所有文章")
    @PostMapping("/all")
    public ResponseResult<List<ApArticle>> findAllArticle(
            @RequestParam(value = "preTime") String preTime,
            @RequestParam(value = "beTime") String beTime) {
        return apArticleService.getAllArtile(preTime,beTime);
    }
    //根据作者查询该作者的所以文章
    @GetMapping("/list/{id}")
    public ResponseResult<List<ApArticle>> findArticleByAuthorId(@PathVariable("id") String id){
        return apArticleService.findArticleByAuthorId(id);
    }
    //查询作者的文章的阅读量,评论量,数据统计的时候使用
    @RequestMapping("/statistics/news")
    public Map statisticsNews(@RequestBody StatisticsDto dto){
        return apArticleService.statisticsNews(dto.getStime(),dto.getEtime(),dto.getAuthorId());
    }
    @RequestMapping("/statistics/news/date")
    public List<ApArticle> findApArticleByDateAndAuthorId(@RequestParam("date")String date, @RequestParam("authorId")String authorId){
        return apArticleService.findApArticleByDateAndAuthorId(date,authorId);
    }
}
